package com.shop.shoporder.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.shop.shoporder.common.HttpRequest;
import com.shop.shoporder.entity.HttpRequestConfig;
import com.shop.shoporder.entity.order.UserNo;
import com.shop.shoporder.service.UserNoService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service("userNoService")
public class UserNoServiceImpl implements UserNoService {


    @Override
    public JSONObject getUserNo(Integer userNoId1) {
        if (userNoId1 > 0) {
//            String url = "http://47.107.180.118:8083/wap/getUserNoInfo";
            String url = HttpRequestConfig.userServerUrl+"/wap/getUserNoInfo";

            String userNoId = "userNoId=" + userNoId1;
            String result = HttpRequest.sendGet(url, userNoId);
            JSONObject str = JSONObject.parseObject(result);
            String code = str.get("code").toString();
            if ("000000".equals(code)) {
                JSONObject strData = JSONObject.parseObject(str.get("data").toString());
                return strData;
            } else {
                return null;
            }
        }else {
            return null;
        }
    }

    @Override
    public List<UserNo> getUserNoList(String userNoIds) {
        if (userNoIds!=null) {
            String url = HttpRequestConfig.userServerUrl+"/wap/getOrderNoList";
            String userNoId = "userNoIds=" + userNoIds;
            String result = HttpRequest.sendGet(url, userNoId);
            JSONObject str = JSONObject.parseObject(result);
            String code = str.get("code").toString();
            if ("000000".equals(code)) {
                List<UserNo> userNoList = JSON.parseArray(str.get("data").toString(), UserNo.class);
                return userNoList;
            } else {
                return null;
            }
        }else {
            return null;
        }
    }

    @Override
    public JSONObject updateRankId(Integer userNoId1, Integer rankId) {
        if (userNoId1 > 0) {
            String url = HttpRequestConfig.userServerUrl+"/wap/getUserNoInfo";
            String userNoId = "userNoId=" + userNoId1+"&rankId="+rankId;
            String result = HttpRequest.sendGet(url, userNoId);
            JSONObject str = JSONObject.parseObject(result);
            String code = str.get("code").toString();
            if ("000000".equals(code)) {
                JSONObject strData = JSONObject.parseObject(str.get("data").toString());
                return strData;
            } else {
                return null;
            }
        }else {
            return null;
        }
    }
}
